<!--vue模板-->
<template>
  <div>
    <!--搜索-->
    <div class="toolbar">
      <el-input
        v-model="filters.customerName"
        placeholder="请输入客户名称"
        clearable
        style="width: 200px; margin-right: 10px"
      />
      &nbsp;
      <el-input
        v-model="filters.mobile"
        placeholder="请输入手机号"
        clearable
        style="width: 200px; margin-right: 10px"
      />
      &nbsp;
      <el-button type="primary" @click="init">查询</el-button>
      <el-button type="primary" @click="reset">重置</el-button>
    </div>
    <!--按钮区-->
    <!--表格数据-->
    <el-table :data="tableData" style="width: 100%" stripe border>
      <el-table-column
        prop="code"
        label="询价单号"
        width="110"
        header-align="center"
        align="center"
      />
      <el-table-column
        prop="type"
        label="询价类型"
        width="110"
        header-align="center"
        align="center"
      />
      <el-table-column
        prop="status"
        label="状态"
        width="80"
        header-align="center"
        align="center"
      >
        <template #default="{ row }">
          <span v-if="row.status === 1">待报价</span>
          <span v-else-if="row.status === 2">已报价</span>
          <span v-else-if="row.status === 3">确认签约</span>
          <span v-else-if="row.status === 4">拒绝合作</span>
          <span v-else>未知状态</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="freight"
        label="运费"
        width="110"
        header-align="center"
        align="center"
      />
      <el-table-column
        prop="price"
        label="总价"
        width="110"
        header-align="center"
        align="center"
      />
      <el-table-column
        prop="modifyDesc"
        label="修改描述"
        width="110"
        header-align="center"
        align="center"
      />
      <el-table-column
        prop="reason"
        label="原因"
        width="110"
        header-align="center"
        align="center"
      />
      <el-table-column
        prop="createTime"
        label="创建时间"
        width="110"
        header-align="center"
        align="center"
      />
      <el-table-column
        label="操作"
        header-align="center"
        align="center"
        width="auto"
      >
        <template #default="{ row }">
          <el-button
            type="primary"
            :icon="Edit"
            circle
            title="查看详情"
            @click="detail(row.id)"
          />
        </template>
      </el-table-column>
    </el-table>

    <!--分页-->
    <div style="height: 60px; line-height: 60px; background-color: #fff">
      <el-pagination
        background
        layout="sizes,total,prev, pager, next,jumper"
        :total="total"
        style="float: right; margin-right: 20px"
        @current-change="chpg"
        @size-change="chsize"
      />
    </div>
    <!--选择产品-->
    <ChooseProduct
      ref="chooseProductRef"
      :visible="isShowChooseProduct"
      @close="isShowChooseProduct = false"
    />
  </div>
</template>

<!--vue 组件选项定义-->
<script setup>
import { ref, onBeforeMount } from "vue";
import { Edit } from "@element-plus/icons-vue";
import { queryEnquiry } from "@/api/Enquiry.js";
import { useRouter } from "vue-router";
import { getUser } from "@/utils/session.js";
import ChooseProduct from "@/views/enquiry/ChooseProduct.vue";
//表格数据
const tableData = ref([]);

//获取路由实例
const router = useRouter();
//分页参数
const page = ref(1); //当前页数
const pageSize = ref(10); //每页记录数
const total = ref(0); //总记录数

//搜索 条件
const filters = ref({
  customerName: "",
  mobile: ""
});

//重置
function reset() {
  filters.value = {
    customerName: "",
    mobile: ""
  };
  init();
}
//是否显示
const isShowChooseProduct = ref(false);
const chooseProductRef = ref(null);
//产品详情
function detail(id) {
  isShowChooseProduct.value = true;
  chooseProductRef.value.clear();
  chooseProductRef.value.initProduct(id);
}
//--选择产品--

// 从登录信息中获取
let user = getUser();
//方法
async function init() {
  let data = {
    page: page.value,
    pageSize: pageSize.value,
    createUserId: user.id,
    mobile: filters.value.mobile
  };
  let res = await queryEnquiry(data);
  if (res.code == 200) {
    console.log(res.data);
    tableData.value = res.data.list;
    page.value = res.data.page;
    pageSize.value = res.data.pageSize;
    total.value = res.data.total;
  }
}

//改变当前页
function chpg(pg) {
  page.value = pg;
  init();
}
//改变每页记录数
function chsize(pgsize) {
  pageSize.value = pgsize;
  page.value = 1;
  init();
}
//生命周期钩子
onBeforeMount(() => {
  init();
});
</script>

<!--vue样式 scoped当前样式只适用于当前组件-->
<style scoped>
.toolbar {
  height: 60px;
  line-height: 60px;
  background-color: #fff;
  padding-left: 20px;
}
</style>
